﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SmartMD.DataAccess.Oracle;
using System.Data;
using SmartMD.DataModel.Entity;
using System.Collections.ObjectModel;
using System.ComponentModel;
using SmartMD.DataAccess.Service;
using System.Collections;
using SmartMD.Manager.Report;


namespace SmartMD.Manager.Patient
{
    /// <summary>
    /// Interaction logic for QueryInfoPanel.xaml
    /// </summary>
    public partial class QueryInfoPanel : UserControl  
    {      
        public QueryInfoPanel()
        {
            InitializeComponent();
            this.ucPatientQueryEdit.Owner = this;
        }

        private void PrintList(ObservableCollection<PatientInfo> pInfoList)
        {
            PrintListView printListView1 = new PrintListView();

            //创建标题
            printListView1.Columns.Add("序号");
            printListView1.Columns.Add("患者姓名");
            printListView1.Columns.Add("首次随访");
            printListView1.Columns.Add("随访人");
            printListView1.Columns.Add("性别");
            printListView1.Columns.Add("年龄");
            printListView1.Columns.Add("地域");
            printListView1.Columns.Add("疾病诊断");

            printListView1.Columns[0].Width = 50;
            printListView1.Columns[1].Width = 110;
            printListView1.Columns[2].Width = 110;
            printListView1.Columns[3].Width = 110;
            printListView1.Columns[4].Width = 110;
            printListView1.Columns[5].Width = 110;
            printListView1.Columns[6].Width = 110;
            printListView1.Columns[7].Width = 110;


            System.Windows.Forms.ImageList imageList1 = new System.Windows.Forms.ImageList();

            //ListView顯示方式
            printListView1.View = System.Windows.Forms.View.Details;
            printListView1.LineSpace = 15;
            printListView1.BeginUpdate();

            int i = 1;
            foreach (PatientInfo sqr in pInfoList)
            {
                printListView1.Items.Add(i.ToString(), i.ToString(), 0);
                printListView1.Items[i.ToString()].SubItems.Add(sqr.Name);
                printListView1.Items[i.ToString()].SubItems.Add(sqr.FirstFollowUpTime.ToString());
                printListView1.Items[i.ToString()].SubItems.Add("");
                printListView1.Items[i.ToString()].SubItems.Add(sqr.Sex);
                printListView1.Items[i.ToString()].SubItems.Add(sqr.Age.ToString());
                printListView1.Items[i.ToString()].SubItems.Add(sqr.Area);
                printListView1.Items[i.ToString()].SubItems.Add("Diagnose");
 
                i++;
            }

            printListView1.EndUpdate();
            printListView1.DoPrint();
        }

        internal void OnWindowActivated()
        {
            //throw new NotImplementedException();
            this.ucPatientQueryEdit.InitAllComboxValue();
        }

        private void btnSelectedPrint_Click(object sender, RoutedEventArgs e)
        {
            if (this.ucPatientQueryList.patientPrintList != null && this.ucPatientQueryList.patientPrintList.Count > 0)
            {
                PrintList(this.ucPatientQueryList.patientPrintList);
            }
        }
        private void btnAllPrint_Click(object sender, RoutedEventArgs e)
        {
            if (this.ucPatientQueryList.PatientList != null && this.ucPatientQueryList.PatientList.Count > 0)
            {
                PrintList(this.ucPatientQueryList.PatientList);
            }
        }

        private void btnExportExcel_Click(object sender, RoutedEventArgs e)
        {
            List<string> patientIds = new List<string>();
            for(int i=0; i<this.ucPatientQueryList.patientPrintList.Count;i++)
            {
               patientIds.Add( this.ucPatientQueryList.patientPrintList[i].Id);
            }
            System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();
            //saveDlg.DefaultExt = "*.xls";
            saveDlg.Title = "导出Excel";
            saveDlg.Filter = "(*.xlsx)|*.xlsx";
            saveDlg.ShowDialog();
       
            ExcelHelper.ExportExcel(saveDlg.FileName, patientIds);    
        }

    }
}
